package com.awei.study.interview.multiThreading;


import lombok.SneakyThrows;
import org.junit.jupiter.api.Test;

import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @Author liweilong
 * @Date 2024/11/27 0:39
 */

public class ThreadTest {

    class CallableChild implements Callable<String> {

        @Override
        public String call() throws Exception {
            Thread.sleep(3000);
            System.out.println("hello start");
            return "hello";
        }
    }

    class RunnableChild implements Runnable {

        @SneakyThrows
        @Override
        public void run() {
//            Thread.sleep(3000);
            System.out.println("hello start");
        }
    }

    @Test
    public void testCallable() throws ExecutionException, InterruptedException {
//        CallableChild c = new CallableChild();
//        FutureTask<String> ft = new FutureTask<>(c);
//        Thread t = new Thread(ft);
//        System.out.println(System.currentTimeMillis());
//        t.start();
//        Thread.sleep(2000);
//        System.out.println(System.currentTimeMillis());
//        String s = ft.get();
//        System.out.println(s);
        System.out.println(System.currentTimeMillis());
        int i = Runtime.getRuntime().availableProcessors();
        System.out.println(i);
    }

    @Test
    public void ThreadPool() {
        ExecutorService threadPool = Executors.newFixedThreadPool(3);
//        threadPool.submit(new RunnableChild());
        threadPool.submit(new CallableChild());
        threadPool.shutdown();
        Executors.newCachedThreadPool();
        Executors.newSingleThreadExecutor();
        Executors.newScheduledThreadPool(100);
    }
}
